//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Configuration;

namespace CommunityServer.Components
{
	/// <summary>
	/// Summary description for MemberUserRoleProvider.
	/// </summary>
	public abstract class MemberRoleProfileProvider
	{
		public MemberRoleProfileProvider()
		{
		}

        private static readonly MemberRoleProfileProvider murp = null;

        static MemberRoleProfileProvider()
        {
            
                CSConfiguration config = CSConfiguration.GetConfig();
                Provider provider = config.Providers["MemberRoleProfileProvider"] as Provider;
                if(provider != null)
                {
                    if(Globals.IsNullorEmpty(provider.Type))
                        throw new Exception("MemberUserRoleProvider provider found, but no type attribute was specified");

                    Type type = Type.GetType(provider.Type);
                    if(type == null)
                        throw new Exception(string.Format("MemberUserRoleProvider Provider Type {0} could not be loaded",provider.Type));

                    murp = Activator.CreateInstance(type) as MemberRoleProfileProvider;
                    if(murp == null)
                        throw new Exception("MemberUserRoleProvider could not be loaded from the type " + provider.Type);
                }
        }

        public static MemberRoleProfileProvider Instance()
        {
            return murp;
        }


        public abstract IRoles Roles { get;}
        public abstract IMembership Members { get;}
        public abstract IProfiles Profiles { get;}
	}

}
